//
//  CZKeyChainHandle.m
//  globalTranslate
//
//  Created by 陈镇 on 2025/8/8.
//

#import "CZKeyChainHandle.h"
#import "YYKeychain.h"

@implementation CZKeyChainHandle


+(void)cz_setValue:(NSString *)value forKey:(NSString *)key{
    [YYKeychain setPassword:value forService:KeyChainKey(key) account:KeyBundleID];
}

+(NSString *)czValueforKey:(NSString *)key{
    return [YYKeychain getPasswordForService:KeyChainKey(key) account:KeyBundleID];
}



+ (NSString *)UUID{
    NSString *uuid = (NSString *)[YYKeychain getPasswordForService:KeyChainKey(@"UUID") account:KeyBundleID];
    //不存在就生成
    if ([uuid isEqualToString:@""] || !uuid){
        //生成一个uuid的方法
        CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
        uuid = (NSString *)CFBridgingRelease(CFUUIDCreateString (kCFAllocatorDefault,uuidRef));
        //将该uuid保存到keychain
        [YYKeychain setPassword:uuid forService:KeyChainKey(@"UUID") account:KeyBundleID];
        CFRelease(uuidRef);
    }
    return uuid;
}



@end
